package com.wsc.wsckeeper.activities.fragments.base;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.LayoutInflater;
import android.view.MenuInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;

import com.wsc.wsckeeper.R;
import com.wsc.wsckeeper.managers.ResourceManager;
import com.wsc.wsckeeper.model.KModel;
import com.wsc.wsckeeper.model.KRuntimeModel;
import com.wsc.wsckeeper.utils.DialogUtils;

public class BaseFragment extends Fragment {
	protected View view;
	protected ListView listView;
	protected KModel model = KModel.getInstance();
	protected KRuntimeModel runtime = KRuntimeModel.getInstance();

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		view = inflater.inflate(R.layout.fragment, container, false);
		init();
		return view;
	}

	public void init() {
		initComponents();
		initValues();
		initListeners();
	//	initUI();
	}

	public void initComponents() {
		listView = (ListView) view.findViewById(R.id.list);
	}

	public void initValues() {

	}

//	public void initUI() {
//
//	}

	public void initListeners() {
	}

	@Override
	public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
		super.onCreateContextMenu(menu, v, menuInfo);
		if (v.getId() == R.id.list) {
			menu.setHeaderTitle(ResourceManager.getStringValue(R.string.menu_choose_action));
			MenuInflater inflater = getActivity().getMenuInflater();
			inflater.inflate(R.menu.menu_context, menu);
		}
	}

	public void showExceptionAsDialog(final Exception e) {
		DialogUtils.showException(getActivity(), e);
	}
}
